package gui;

import java.io.PrintWriter;
import java.io.StringWriter;

import javax.swing.JDialog;

/**
 * 
 * @author Alexey Kuprin
 * 
 */

public class ExceptionHandler {
	public static void handleException(Exception e, String message) {
		JDialog modalDialog = new Notification(e, message);
		modalDialog.setVisible(true);
	}

	public static void handleException(Exception e) {
		handleException(e, e.getMessage());
	}

	/**
	 * Gets the exception stack trace as a string.
	 */
	public static String getStackTraceAsString(Exception exception) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		pw.print("[");
		pw.print(exception.getClass().getName());
		pw.print("]");
		pw.print(exception.getMessage());
		exception.printStackTrace(pw);

		return sw.toString();
	}
}
